home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / memspd.zip / MEMSPDA.A < prev   
Text File  |  1993-03-31  |  10KB  |  740 lines

  1. ;*M* MEMSPDA - Memory speed measurer subroutines
  2. ;
  3.     ise    386
  4. ;
  5. ;
  6. ;
  7. ; Includes
  8. ;
  9.     include    hka7kbat.aim
  10.     include    hb7bios.aim
  11.     include    hma7mthb.aim
  12. ;
  13. ;
  14. ;
  15. ; Defs
  16. ;
  17.     entry    ADDRH
  18.     entry    IORDB
  19.     entry    IORDW
  20.     entry    LOAD
  21.     entry    LOADEM
  22.     entry    LOADH
  23.     entry    MEML
  24.     entry    MEMH
  25.     entry    STORB
  26.     entry    STORW
  27.     entry    interval
  28. ;
  29. ;
  30. ;
  31. ; Refs
  32. ;
  33.     extrn    USR
  34. ;
  35. ;
  36. ;
  37. ; Macros
  38. ;
  39.     MACRO
  40.     setoff
  41.     xor    si,si
  42.     xor    di,di
  43.     mov    cx,CNT
  44.     ENDM
  45. ;
  46. ;
  47. ;
  48. code:    rel
  49. ;
  50. data:    rel
  51. ;
  52. CNT    equ    800H    ; must be at least 200H
  53. ;
  54. stack    ds    100H
  55. stkend    equ    $
  56. clkval    dw    0
  57. clkval1    dw    0
  58. interval    dw    0,0
  59. intervalb dw    0
  60. myds    dw    0
  61.     align    8
  62. gdtr    ds    8
  63. gdt    ds    6*8
  64.     align    4
  65. bfr    ds    CNT
  66. ;
  67. ;
  68.     using
  69. ;
  70.     ds    256
  71. start    equ    $
  72. ;
  73.     nop
  74.     mov    ax,cs
  75.     mov    ds,ax
  76.     mov    ss,ax
  77.     mov    sp,stkend
  78.     mov    es,ax
  79.     cld
  80. ;
  81.     call    USR
  82. ;
  83.     mov    ah,4CH
  84.     int    21H
  85. ;
  86. ;
  87. ;
  88. ADDRH    equ    $
  89. ;
  90.     call    .kbwait    ; wait for OK to write
  91.     mov    al,0D1h    ; enable access to mem above the A20 line
  92.     out    (64h),al
  93.     call    .kbwait
  94.     mov    al,0DFh
  95.     out    (60h),al
  96. ;
  97.     mov    bx,1
  98.     push    ds
  99.     push    es
  100.     xor    ax,ax
  101.     mov    ds,ax
  102.     dec    ax
  103.     mov    es,ax
  104.     xor    si,si
  105.     mov    di,10H
  106.     mov    cx,800H
  107.     cli
  108.     repz
  109.     cmps
  110.     pop    es
  111.     pop    ds
  112.     je    .$10
  113.     dec    bx
  114. .$10:    ret
  115. ;
  116. .kbwait    equ    $
  117.     in    al,(64H)    ; spin until data has been accepted
  118.     test    al,02H
  119.     jnz    .kbwait
  120.     ret
  121. ;
  122. ;
  123. ;
  124. P$SEG    value    8
  125. P$FLG    value    6
  126. P$SIZ    value    4
  127. ;
  128. LOAD    equ    $
  129.     push    bp
  130.     mov    bp,sp
  131. ;
  132.     push    es
  133.     cli
  134.     mov    es,(bp+P$SEG)
  135.     call    disrupt
  136.     xor    si,si
  137.     mov    cx,1000H
  138.     cmpw    (bp+P$FLG),0
  139.     jne    .$10
  140.     cmpw    (bp+P$SIZ),1
  141.     je    .$07
  142.     ja    .$08
  143.     rep
  144.     lods    es:
  145.     jmpr    .$10
  146. .$07:    rep
  147.     lodsw    es:
  148.     jmpr    .$10
  149. .$08:    rep
  150.     lodsw,eo    es:
  151. ;
  152. .$10:    xor    si,si
  153.     mov    cx,1000H
  154.     call    inittime
  155.     cmpw    (bp+P$SIZ),1
  156.     je    .$12
  157.     ja    .$14
  158.     rep
  159.     lods    es:
  160.     jmpr    .$16
  161. .$12:    rep
  162.     lodsw    es:
  163.     jmpr    .$16
  164. .$14:    rep
  165.     lodsw,eo    es:
  166. .$16:    call    calctime
  167.     sti
  168. ;
  169.     pop    es
  170. ;
  171.     mov    ax,(interval)
  172.     cmpw    (bp+P$SIZ),0
  173.     jne    .$19
  174.     shr    ax
  175.     mov    (intervalb),ax    ; save byte time / 2
  176.     jmpr    .$21
  177. .$19:    cmp    ax,(intervalb)
  178.     ja    .$21
  179.     incw    (interval+2)
  180. ;
  181. .$21:    mov    ax,84
  182.     mulw    (interval)    ; convert clock tics to usec
  183.     cmpw    (interval+2),0
  184.     je    .$23
  185.     add    dx,84/2
  186. .$23:    mov    cx,1000H
  187.     div    cx    ; get usec per xaction * 100
  188. ;
  189.     mov    bx,ax
  190.     pop    bp
  191.     ret    6
  192. ;
  193. ;
  194. ;
  195. P$SEG    value    8
  196. P$FLG    value    6
  197. P$SIZ    value    4
  198. ;
  199. LOADH    equ    $
  200.     push    bp
  201.     mov    bp,sp
  202. ;
  203.     push    es
  204.     cli
  205. ;
  206.     mov    ax,0FFFFH
  207.     mov    es,ax
  208.     call    disrupt
  209.     mov    cx,1000H
  210.     mov    si,100H
  211.     cmpw    (bp+P$FLG),0
  212.     jne    .$10
  213.     cmpw    (bp+P$SIZ),1
  214.     je    .$07
  215.     ja    .$08
  216.     rep
  217.     lods    es:
  218.     jmpr    .$10
  219. .$07:    rep
  220.     lodsw    es:
  221.     jmpr    .$10
  222. .$08:    rep
  223.     lodsw,eo    es:
  224. ;
  225. .$10:    
  226.     mov    cx,1000H
  227.     mov    si,100H
  228.     call    inittime
  229.     cmpw    (bp+P$SIZ),1
  230.     je    .$12
  231.     ja    .$14
  232.     rep
  233.     lods    es:
  234.     jmpr    .$16
  235. .$12:    rep
  236.     lodsw    es:
  237.     jmpr    .$16
  238. .$14:    rep
  239.     lodsw,eo    es:
  240. .$16:    call    calctime
  241.     sti
  242. ;
  243.     pop    es
  244. ;
  245.     mov    ax,(interval)
  246.     cmpw    (bp+P$SIZ),0
  247.     jne    .$19
  248.     shr    ax
  249.     mov    (intervalb),ax    ; save byte time / 2
  250.     jmpr    .$21
  251. .$19:    cmp    ax,(intervalb)
  252.     ja    .$21
  253.     incw    (interval+2)
  254. ;
  255. .$21:    mov    ax,84
  256.     mulw    (interval)    ; convert clock tics to usec
  257.     cmpw    (interval+2),0
  258.     je    .$23
  259.     add    dx,84/2
  260. .$23:    mov    cx,1000H
  261.     div    cx    ; get usec per xaction * 100
  262. ;
  263.     pop    bp
  264.     mov    bx,ax
  265.     ret    6
  266. ;
  267. ;
  268. ;
  269. P$BASE    value    8
  270. P$FLG    value    6
  271. P$SIZ    value    4
  272. ;
  273. LOADEM    equ    $
  274.     push    bp
  275.     mov    bp,sp
  276. ;
  277.     push    es
  278.     mov    eax,(bp+P$BASE)    ; init extra seg selector with this base
  279.     call    setgdt
  280.     call    goprot    ; go into protected mode, disable
  281.     mov    ax,3*8    ; selector of extra segment
  282.     mov    es,ax
  283.     call    disruptem
  284.     xor    si,si
  285.     mov    cx,1000H
  286.     cmpw    (bp+P$FLG),0
  287.     jne    .$10
  288.     cmpw    (bp+P$SIZ),1
  289.     je    .$07
  290.     ja    .$08
  291.     rep
  292.     lods    es:
  293.     jmpr    .$10
  294. .$07:    rep
  295.     lodsw    es:
  296.     jmpr    .$10
  297. .$08:    rep
  298.     lodsw,eo    es:
  299. ;
  300. .$10:    xor    si,si
  301.     mov    cx,1000H
  302.     call    inittime
  303.     cmpw    (bp+P$SIZ),1
  304.     je    .$12
  305.     ja    .$14
  306.     rep
  307.     lods    es:
  308.     jmpr    .$16
  309. .$12:    rep
  310.     lodsw    es:
  311.     jmpr    .$16
  312. .$14:    rep
  313.     lodsw,eo    es:
  314. .$16:    call    calctime
  315.     call    goreal    ; go back into real mode, enable
  316. ;
  317.     pop    es
  318. ;
  319.     mov    ax,(interval)
  320.     cmpw    (bp+P$SIZ),0
  321.     jne    .$19
  322.     shr    ax
  323.     mov    (intervalb),ax    ; save byte time / 2
  324.     jmpr    .$21
  325. .$19:    cmp    ax,(intervalb)
  326.     ja    .$21
  327.     incw    (interval+2)
  328. ;
  329. .$21:    mov    ax,84
  330.     mulw    (interval)    ; convert clock tics to usec
  331.     cmpw    (interval+2),0
  332.     je    .$23
  333.     add    dx,84/2
  334. .$23:    mov    cx,1000H
  335.     div    cx    ; get usec per xaction * 100
  336. ;
  337.     mov    bx,ax
  338.     pop    bp
  339.     ret    8
  340. ;
  341. ;
  342. ;
  343. MEMH    equ    $
  344. ;
  345.     mov    ah,88H
  346.     int    15H
  347.     mov    bx,ax
  348.     test    bh,80H
  349.     je    .$20
  350.     xor    bx,bx    ; none
  351. .$20:    or    bx,bx
  352.     je    .$30    ; none
  353. ;
  354.     cli
  355.     mov    al,0D1h    ; enable access to mem above the A20 line
  356.     out    (64h),al
  357.     jmpr    $+2
  358. .wrbusy    in    al,(HKA9Rstat)    ; spin until data has been accepted
  359.     test    al,HKA9Srdry
  360.     jnz    .wrbusy
  361.     mov    al,HKA9OPa20
  362.     out    (HKA9Rdata),al
  363.     sti
  364. ;
  365. .$30:    ret        ; return extended mem size in K
  366. ;
  367. ;
  368. ;
  369. MEML    equ    $
  370. ;
  371.     int    HB9Imsiz    ; get mem size in K excluding BIOS ext mem
  372.     add    ax,63
  373.     and    ax,-64    ; round up
  374.     mov    bx,ax
  375.     ret
  376. ;
  377. ;
  378. ;
  379. STORB    equ    $
  380. ;
  381.     push    ds
  382.     pop    es
  383.     cli
  384.     mov    di,bfr
  385.     mov    cx,CNT
  386.     call    inittime
  387.     rep
  388.     stos
  389.     call    calctime
  390.     sti
  391. ;
  392.     mov    ax,84
  393.     mulw    (interval)    ; convert clock tics to usec
  394.     mov    cx,CNT
  395.     div    cx    ; get usec per xaction * 100
  396. ;
  397.     mov    bx,ax
  398.     ret
  399. ;
  400. ;
  401. ;
  402. STORW    equ    $
  403. ;
  404.     push    ds
  405.     pop    es
  406.     cli
  407.     mov    di,bfr
  408.     mov    cx,CNT/2
  409.     call    inittime
  410.     rep
  411.     stosw
  412.     call    calctime
  413.     sti
  414. ;
  415.     mov    ax,84
  416.     mulw    (interval)    ; convert clock tics to usec
  417.     mov    cx,CNT/2
  418.     div    cx    ; get usec per xaction * 100
  419. ;
  420.     mov    bx,ax
  421.     ret
  422. ;
  423. ;
  424. ;
  425. P$IOA    value    4
  426. ;
  427. IORDB    equ    $
  428.     push    bp
  429.     mov    bp,sp
  430. ;
  431.     push    ds
  432.     pop    es
  433.     cli
  434.     mov    di,bfr
  435.     mov    cx,CNT
  436.     mov    dx,(bp+P$IOA)
  437.     call    inittime
  438.     rep
  439.     ins
  440.     call    calctime
  441.     sti
  442. ;
  443.     mov    ax,84
  444.     mulw    (interval)    ; convert clock tics to usec
  445.     mov    cx,CNT
  446.     div    cx    ; get usec per xaction * 100
  447. ;
  448.     mov    bx,ax
  449.     pop    bp
  450.     ret    2
  451. ;
  452. ;
  453. ;
  454. P$IOA    value    4
  455. ;
  456. IORDW    equ    $
  457.     push    bp
  458.     mov    bp,sp
  459. ;
  460.     push    ds
  461.     pop    es
  462.     cli
  463.     mov    dx,(bp+P$IOA)
  464.     cmp    dx,1F0H
  465.     je    .$08
  466.     cmp    dx,170H
  467.     jne    .$10
  468. .$08:    call    setdisk
  469. .$10:    
  470.     mov    di,bfr
  471.     if    CNT.lt.200H
  472.     error    'CNT is too small'
  473.     endif
  474.     mov    cx,200H/2
  475.     call    inittime
  476.     rep
  477.     insw
  478.     call    calctime
  479.     sti
  480. ;
  481.     mov    ax,84
  482.     mulw    (interval)    ; convert clock tics to usec
  483.     mov    cx,200H/2
  484.     div    cx    ; get usec per xaction * 100
  485. ;
  486.     mov    bx,ax
  487.     pop    bp
  488.     ret    2
  489. ;
  490. ;
  491. setdisk    equ    $
  492. ;
  493.     push    dx
  494.     add    dx,2
  495.     mov    al,1
  496.     out    (dx),al    ; # sectors
  497.     jmpr    $+2
  498.     inc    dx
  499.     out    (dx),al    ; sector #
  500.     jmpr    $+2
  501.     inc    dx
  502.     xor    al,al
  503.     out    (dx),al    ; cyl low
  504.     jmpr    $+2
  505.     inc    dx
  506.     out    (dx),al    ; cyl high
  507.     jmpr    $+2
  508.     inc    dx
  509.     mov    al,0A0H
  510.     out    (dx),al    ; drive select, head select
  511.     jmpr    $+2
  512.     inc    dx
  513.     mov    al,20H
  514.     out    (dx),al    ; read command
  515.     mov    cx,200H
  516.     loop    $
  517. .$15:    in    al,(dx)
  518.     test    al,80H
  519.     je    .$18
  520.     loop    .$15
  521. .$18:    test    al,8
  522.     jne    .$20    ; wait for DRQ
  523.     loop    .$15
  524. .$20:    mov    cx,100H
  525.     loop    $
  526.     pop    dx
  527.     ret
  528. ;
  529. ;
  530. ;
  531. ;*D* NAME:    inittime
  532. ;*D* CALL:    call inittime
  533. ;*D* DESCRIPTION:    Disables, reads the current clock value, and saves it
  534. ;*D*        in CLKVAL.
  535. ;
  536. inittime    equ    $
  537. ;
  538.     call    gettime
  539.     mov    (clkval),ax
  540.     ret
  541. ;
  542. ;
  543. ;
  544. ;*D* NAME:    calctime
  545. ;*D* CALL:    call calctime
  546. ;*D* DESCRIPTION:    Reads the current clock value, subtracts it from the
  547. ;*D*        value in CLKVAL, enables and returns the result.
  548. ;*D*        If sign bit is set, the result is not meaningful.
  549. ;
  550. calctime    equ    $
  551.     call    gettime
  552.     mov    (clkval1),ax
  553.     neg    ax
  554.     add    ax,(clkval)
  555.     shr    ax
  556.     mov    (interval),ax
  557.     movw    (interval+2),0
  558.     ret
  559. ;
  560. ;
  561. ;
  562. ;*D* NAME:    gettime
  563. ;*D* CALL:    call gettime
  564. ;*D* DESCRIPTION:    Gets the current clock value.
  565. ;
  566. gettime    equ    $
  567. ;
  568.     mov    al,HMA9TClat+HMA9TCc0
  569.     out    (HMA9TBpri+HMA9TRctl),al
  570.     jmpr    $+2
  571.     in    al,(HMA9TBpri+HMA9TR0)
  572.     mov    ah,al
  573.     jmpr    $+2
  574.     in    al,(HMA9TBpri+HMA9TR0)
  575.     xchg    al,ah
  576.     ret
  577. ;
  578. ;
  579. ;
  580. ;*D* NAME:    disrupt
  581. ;*D* CALL:    call disrupt
  582. ;*D* DESCRIPTION:    If the segment being tested is >= 2000H, loads 64K from
  583. ;*D*        1000H and then 0000H, else loads 64K from 3000H and then
  584. ;*D*        2000H.  The intent is to get all data from the segment
  585. ;*D*        being tested out of the cache.
  586. ;
  587. disrupt    equ    $
  588. ;
  589.     std
  590.     push    es
  591.     mov    ax,es
  592.     cmp    ax,2000H
  593.     jae    .$05
  594.     mov    bx,3000H
  595.     jmpr    .$10
  596. .$05:    mov    bx,1000H
  597. .$10:    mov    es,bx
  598.     mov    si,0FFFEH
  599.     mov    cx,8000H
  600.     rep
  601.     lodsw    es:
  602.     sub    bx,1000H
  603.     test    bh,10H
  604.     je    .$10
  605.     pop    es
  606.     cld
  607.     ret
  608. ;
  609. ;
  610. ;
  611. ;*D* NAME:    disruptem
  612. ;*D* CALL:    call disruptem
  613. ;*D* DESCRIPTION:    Loads 128K starting at real mem zero in order to disrupt
  614. ;*D*        the cache.
  615. ;
  616. disruptem equ    $
  617. ;
  618.     push    es
  619.     mov    ax,4*8    ; GDT 4
  620.     mov    es,ax
  621.     xor    si,si
  622.     mov    cx,8000H
  623.     rep
  624.     lodsw    es:
  625.     mov    ax,5*8    ; GDT 5
  626.     mov    es,ax
  627.     xor    si,si
  628.     mov    cx,8000H
  629.     rep
  630.     lodsw    es:
  631.     pop    es
  632.     ret
  633. ;
  634. ;
  635. ;
  636. goprot    equ    $
  637. ;
  638.     mov    (myds),ds
  639.     mov    (gorcs),cs
  640.     cli
  641.     push    eax
  642.     lgdt    (gdtr)
  643.     mov    eax,cr0
  644.     or    al,1
  645.     mov    cr0,eax
  646.     jmpr    $+2
  647.     mov    ax,2*8    ; data selector
  648.     mov    ss,ax
  649.     mov    ds,ax
  650.     mov    es,ax
  651.     jmpl    .gop10,1*8
  652. .gop10:    pop    eax
  653.     ret
  654. ;
  655. ;
  656. ;
  657. goreal    equ    $
  658. ;
  659.     push    eax
  660.     push    cx
  661.     mov    cx,(myds)
  662.     mov    eax,cr0
  663.     and    al,.not.1
  664.     mov    cr0,eax
  665.     jmpl    gor10,0
  666. gorcs    equ    $-2
  667. gor10:    mov    ds,cx
  668.     mov    es,cx
  669.     mov    ss,cx
  670.     pop    cx
  671.     pop    eax
  672.     sti
  673.     ret
  674. ;
  675. ;
  676. ;
  677. setgdt    equ    $
  678. ;
  679.     push    eax
  680.     push    ebx
  681.     push    ecx
  682. ;
  683.     push    eax
  684. ;
  685.     movw    (gdtr),(6*8)-1    ; GDT limit
  686.     xor    ebx,ebx
  687.     mov    bx,ds
  688.     shl    ebx,4
  689.     xor    ecx,ecx
  690.     mov    cx,gdt
  691.     add    ebx,ecx
  692.     mov    (gdtr+2),ebx    ; GDT base
  693. ;
  694.     mov    di,gdt+8    ; GDT 1:  Code descriptor
  695.     movw    (di),0FFFFH
  696.     mov    cx,cs
  697.     shl    cx,4
  698.     mov    (di+2),cx    ; low of base
  699.     mov    cx,cs
  700.     shr    cx,12
  701.     mov    (di+4),cl    ; middle of base
  702.     mov    (di+5),9BH    ; present, data/code, executable, code, used
  703. ;
  704.     mov    di,gdt+16    ; GDT 2:  Data descriptor
  705.     movw    (di),0FFFFH
  706.     mov    cx,ds
  707.     shl    cx,4
  708.     mov    (di+2),cx    ; low of base
  709.     mov    cx,ds
  710.     shr    cx,12
  711.     mov    (di+4),cl    ; middle of base
  712.     mov    (di+5),93H    ; present, data/code, data, used
  713. ;
  714.     mov    di,gdt+24    ; GDT 3:  Extra descriptor
  715.     movw    (di),0FFFFH
  716.     pop    eax
  717.     mov    (di+2),ax    ; low of base
  718.     shr    eax,16
  719.     mov    (di+4),al    ; middle of base
  720.     mov    (di+5),93H    ; present, data/code, data, used
  721. ;
  722.     mov    di,gdt+32    ; GDT 4:  Low 64K descriptor
  723.     movw    (di),0FFFFH
  724.     movw    (di+2),0    ; low of base
  725.     mov    (di+4),0    ; middle of base
  726.     mov    (di+5),93H    ; present, data/code, data, used
  727. ;
  728.     mov    di,gdt+40    ; GDT 5:  Next 64K descriptor
  729.     movw    (di),0FFFFH
  730.     movw    (di+2),0    ; low of base
  731.     mov    (di+4),1    ; middle of base
  732.     mov    (di+5),93H    ; present, data/code, data, used
  733. ;
  734.     pop    ecx
  735.     pop    ebx
  736.     pop    eax
  737.     ret
  738. ;
  739.     end    start
  740.